package com.yricky.indesk.ui.compose

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.KeyboardArrowLeft
import androidx.compose.material.icons.rounded.KeyboardArrowRight
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.yricky.indesk.ui.compose.shapes.RoundRect

/**
 * @author Yricky
 * @date 2021/12/26
 */
@Preview
@Composable
fun BottomBar(
    modifier: Modifier = Modifier,
    text:String = "2021-12-26",
    content:@Composable RowScope.()->Unit = {}
){
    Row(modifier = modifier
        .background(Color(0xff000000), shape = RoundRect.r(6))
        .padding(2.dp)
        .background(Color(0xffffffff), shape = RoundRect.r(4))
        .padding(4.dp),
    verticalAlignment = Alignment.CenterVertically) {
        Text(text = text, fontSize = 24.sp)
        Spacer(modifier = Modifier.weight(1f))
        content(this)

    }
}

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun PageIndicator(
    modifier: Modifier = Modifier,
    index:Int = 0, count:Int = 1,
    onFlip:(Int)->Unit = {},
    onFlipLongClick: (Int) -> Unit = {}
){
    Row(modifier = modifier,
        verticalAlignment = Alignment.CenterVertically
    ) {
        Icon(
            modifier = Modifier.size(36.dp)
                .combinedClickable(
                    onClick = { onFlip(if (index == 0) (count - 1) else (index - 1)) },
                    onLongClick = { onFlipLongClick(if (index == 0) (count - 1) else (index - 1)) }
                ),
            imageVector = Icons.Rounded.KeyboardArrowLeft,
            contentDescription = "")
        Text("${index+1}/$count")
        Icon(
            modifier = Modifier
                .size(36.dp)
                .combinedClickable(
                    onClick = { onFlip(if (index == count - 1) 0 else (index + 1)) },
                    onLongClick = { onFlipLongClick(if (index == count - 1) 0 else (index + 1)) }
                ),
            imageVector = Icons.Rounded.KeyboardArrowRight,
            contentDescription = "")
    }
}
